//
//  MXNewViewContentCollectionViewCell.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/8.
//  Copyright (c) 2015年 霄 马. All rights reserved.
//

#import "MXNewViewContentCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "MXNewViewItemDetailModel.h"
@implementation MXNewViewContentCollectionViewCell
- (void)dealloc
{
    [_modelS release];
    [_itemImage release];
    [_priceLabel release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.itemImage = [[[UIImageView alloc] init] autorelease];
        self.itemImage.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:self.itemImage];
        
        self.priceLabel = [[[UILabel alloc] init] autorelease];
        self.priceLabel.backgroundColor = [UIColor clearColor];
        self.priceLabel.font = [UIFont systemFontOfSize:14];
        [self.priceLabel setTextColor:[UIColor blackColor]];
        self.priceLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.priceLabel];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat WID = self.frame.size.width;
    CGFloat margin = 10;
    
    CGFloat ImageX = 0;
    CGFloat ImageY = 0;
    CGFloat ImageW = WID;
    CGFloat ImageH = WID;
    
    self.itemImage.frame = CGRectMake(ImageX, ImageY, ImageW, ImageH);
    
    CGFloat priceLabelX = margin;
    CGFloat priceLabelY = WID - HEIGHTPRO * 30;
    CGFloat priceLabelW = WIDTHPRO * 60;
    CGFloat priceLabelH = HEIGHTPRO * 20;
    self.priceLabel.frame = CGRectMake(priceLabelX, priceLabelY, priceLabelW, priceLabelH);
}

- (void)GetInfo:(MXProductsModel *)model
{
    if (_modelS != model) {
        [_modelS release];
        _modelS = [model retain];
    }
    [self.itemImage sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@"plaseholder"]];
    
    CGFloat price = [model.price floatValue];
    
    self.priceLabel.text = [NSString stringWithFormat:@"¥%.0f", price];
    
}
@end
